﻿using System.Web;
using System.Web.Mvc;
using CkSoftware.GroupMe.Sdk.Core.Dao;

namespace CkSoftware.GroupMe.Sdk.TestWeb.Helpers
{
	public static class HtmlHelperExtensions
	{
		public static IHtmlString AvatarImageForGroupMePicture(this HtmlHelper htmlHelper, PictureData picture, string altText = "")
		{
			var imageBuilder = new TagBuilder("img");

			imageBuilder.Attributes.Add("alt", altText);
			imageBuilder.Attributes.Add("src", picture.AvatarUrl);

			return new MvcHtmlString(imageBuilder.ToString(TagRenderMode.SelfClosing));
		}

		public static IHtmlString TextOrDash(this HtmlHelper htmlHelper, string text)
		{
			if (string.IsNullOrWhiteSpace(text))
			{
				return new HtmlString("&ndash;");
			}

			return new HtmlString(HttpUtility.HtmlEncode(text));
		}
	}
}